<?php

namespace App\Observers;
use App\Models\SinInLog;
use App\Models\Coupon;
use App\Models\CouponsConfig;
use App\Models\IntegralRule;
use Illuminate\Support\Facades\Auth;
class SinInLogObserver
{
    /**
     * Handle the user "created" event.
     *
     * @param  \App\User  $user
     * @return void
     */
    public function created(SinInLog $sinInLog)
    {
//        dd($sinInLog->user->sin_in_day);
        //变更用户信息
        $sinInLog->user->sin_in_day++;
        $sinInLog->user->last_sign_date = date("Y-m-d");
        $sinInLog->user->save();

        //签到赠送积分数
        $integral = IntegralRule::getSignInIntegral();

        //积分记录增加

        $data['integral'] = $integral;
        Auth::guard("api")->user()->userIntegralLogs()->create([
            "integral"=>$integral,
            "des"     =>"签到获取",
            "recoder" =>"系统",
            "checker" =>"系统",
            "is_checked" => true,
        ]);
//        Auth::guard("api")->user()->userIntegral()->increment("integral",$integral);
    }
}
